package com.homework.datastorageandshare;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class UseCount extends Activity{
    SharedPreferences preferences;
    Button turn=null;
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        preferences = getSharedPreferences("count", MODE_PRIVATE);
        //读取SharedPreferences里的count数据
        int count =preferences.getInt("count" , 0);
        //显示程序以前使用的次数
        Toast.makeText(this , "程序以前被使用了" + count + "次。", 10000).show();
        Editor editor =getSharedPreferences("count" ,  Context.MODE_PRIVATE).edit();
        //存入数据
        editor.putInt("count" , ++count);
        //提交修改
        editor.apply();

        turn=(Button) findViewById(R.id.button_jump);

        turn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UseCount.this, DBTest.class);
                startActivity(intent);
            }
        });
    }
}
